/*
 * Created by SharpDevelop.
 * User: Administrator
 * Date: 26-03-2009
 * Time: 11:54
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;


namespace Plain.Utilities
{
	/// <summary>
	/// Description of QueryExtensions.
	/// </summary>
	public static class QueryExtensions{
		public static IEnumerable<TT> findControl<T,TT>(this T o) where T : System.Web.UI.Control where TT: System.Web.UI.Control{
			List<object> beenThere = new List<object>();
			IList<TT> list = new List<TT>();
			HandleObject<TT>(o,list,beenThere);
			return (list);
		}
		private static void HandleObject<T>(System.Web.UI.Control o,IList<T> list, IList<object> beenThere) where T: System.Web.UI.Control{
			if(o is T){
				list.Add((T)o);
			}
			foreach(System.Web.UI.Control  control in  o.Controls){
				HandleObject<T>(control,list,beenThere);
			}
		}
	}
	
}
